#include<iostream>
#include<string>
#include<vector>

using namespace std;

vector<int>path;
vector<vector<int> >result;

void backtracking(int nums_size,vector<int>used,int nums[]){
	if(path.size()==nums_size){
		result.push_back(path);
	}
	
	for(int i=0;i<nums_size;i++){
		if(used[i]==0){
			used[i]=1;
			path.push_back(nums[i]);
	     	backtracking(nums_size,used,nums);
		    path.pop_back();
			used[i]=0;		
		}

	}
}

int main()
{
	int nums[]={1,2,3,5,6,9};
	int nums_size=sizeof(nums)/sizeof(nums[0]);
	vector<int>used;
	for(int i=0;i<nums_size;i++){
		used.push_back(0);
	}
    backtracking(nums_size,used,nums);
    for(vector<vector<int> >::iterator it=result.begin();it!=result.end();it++){
    	for(vector<int>::iterator iit=(*it).begin();iit!=(*it).end();iit++){
    		cout<<*iit<<' ';
		}
		cout<<endl;
	}
	return 0;
 } 
 
 
 
 
 
 
